<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Voro++: wall.cc Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Voro++
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript" src="dynsections.js"></script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">wall.cc</div>  </div>
</div>
<div class="contents">
<a href="wall_8cc.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Voro++, a 3D cell-based Voronoi library</span>
<a name="l00002"></a>00002 <span class="comment">//</span>
<a name="l00003"></a>00003 <span class="comment">// Author   : Chris H. Rycroft (LBL / UC Berkeley)</span>
<a name="l00004"></a>00004 <span class="comment">// Email    : chr@alum.mit.edu</span>
<a name="l00005"></a>00005 <span class="comment">// Date     : August 30th 2011</span>
<a name="l00006"></a>00006 <span class="comment"></span>
<a name="l00007"></a>00007 <span class="comment">/** \file wall.cc</span>
<a name="l00008"></a>00008 <span class="comment"> * \brief Function implementations for the derived wall classes. */</span>
<a name="l00009"></a>00009 
<a name="l00010"></a>00010 <span class="preprocessor">#include &quot;<a class="code" href="wall_8hh.html" title="Header file for the derived wall classes.">wall.hh</a>&quot;</span>
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 <span class="keyword">namespace </span>voro {
<a name="l00013"></a>00013 <span class="comment"></span>
<a name="l00014"></a>00014 <span class="comment">/** Tests to see whether a point is inside the sphere wall object.</span>
<a name="l00015"></a>00015 <span class="comment"> * \param[in,out] (x,y,z) the vector to test.</span>
<a name="l00016"></a>00016 <span class="comment"> * \return True if the point is inside, false if the point is outside. */</span>
<a name="l00017"></a><a class="code" href="structvoro_1_1wall__sphere.html#a08695201299833a5ccebecc016fe8413">00017</a> <span class="keywordtype">bool</span> <a class="code" href="structvoro_1_1wall__sphere.html#a08695201299833a5ccebecc016fe8413">wall_sphere::point_inside</a>(<span class="keywordtype">double</span> x,<span class="keywordtype">double</span> y,<span class="keywordtype">double</span> z) {
<a name="l00018"></a>00018         <span class="keywordflow">return</span> (x-xc)*(x-xc)+(y-yc)*(y-yc)+(z-zc)*(z-zc)&lt;rc*rc;
<a name="l00019"></a>00019 }
<a name="l00020"></a>00020 <span class="comment"></span>
<a name="l00021"></a>00021 <span class="comment">/** Cuts a cell by the sphere wall object. The spherical wall is approximated by</span>
<a name="l00022"></a>00022 <span class="comment"> * a single plane applied at the point on the sphere which is closest to the center</span>
<a name="l00023"></a>00023 <span class="comment"> * of the cell. This works well for particle arrangements that are packed against</span>
<a name="l00024"></a>00024 <span class="comment"> * the wall, but loses accuracy for sparse particle distributions.</span>
<a name="l00025"></a>00025 <span class="comment"> * \param[in,out] c the Voronoi cell to be cut.</span>
<a name="l00026"></a>00026 <span class="comment"> * \param[in] (x,y,z) the location of the Voronoi cell.</span>
<a name="l00027"></a>00027 <span class="comment"> * \return True if the cell still exists, false if the cell is deleted. */</span>
<a name="l00028"></a>00028 <span class="keyword">template</span>&lt;<span class="keyword">class</span> v_cell&gt;
<a name="l00029"></a><a class="code" href="structvoro_1_1wall__sphere.html#a3779ab19fab2ed104f8a8c0bdb5773b4">00029</a> <span class="keywordtype">bool</span> <a class="code" href="structvoro_1_1wall__sphere.html#a3779ab19fab2ed104f8a8c0bdb5773b4">wall_sphere::cut_cell_base</a>(v_cell &amp;c,<span class="keywordtype">double</span> x,<span class="keywordtype">double</span> y,<span class="keywordtype">double</span> z) {
<a name="l00030"></a>00030         <span class="keywordtype">double</span> xd=x-xc,yd=y-yc,zd=z-zc,dq;
<a name="l00031"></a>00031         dq=xd*xd+yd*yd+zd*zd;
<a name="l00032"></a>00032         <span class="keywordflow">if</span> (dq&gt;1e-5) {
<a name="l00033"></a>00033                 dq=2*(sqrt(dq)*rc-dq);
<a name="l00034"></a>00034                 <span class="keywordflow">return</span> c.nplane(xd,yd,zd,dq,w_id);
<a name="l00035"></a>00035         }
<a name="l00036"></a>00036         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00037"></a>00037 }
<a name="l00038"></a>00038 <span class="comment"></span>
<a name="l00039"></a>00039 <span class="comment">/** Tests to see whether a point is inside the plane wall object.</span>
<a name="l00040"></a>00040 <span class="comment"> * \param[in] (x,y,z) the vector to test.</span>
<a name="l00041"></a>00041 <span class="comment"> * \return True if the point is inside, false if the point is outside. */</span>
<a name="l00042"></a><a class="code" href="structvoro_1_1wall__plane.html#a8168f370f6817ccbd4870b1494b4321d">00042</a> <span class="keywordtype">bool</span> <a class="code" href="structvoro_1_1wall__plane.html#a8168f370f6817ccbd4870b1494b4321d">wall_plane::point_inside</a>(<span class="keywordtype">double</span> x,<span class="keywordtype">double</span> y,<span class="keywordtype">double</span> z) {
<a name="l00043"></a>00043         <span class="keywordflow">return</span> x*xc+y*yc+z*zc&lt;ac;
<a name="l00044"></a>00044 }
<a name="l00045"></a>00045 <span class="comment"></span>
<a name="l00046"></a>00046 <span class="comment">/** Cuts a cell by the plane wall object.</span>
<a name="l00047"></a>00047 <span class="comment"> * \param[in,out] c the Voronoi cell to be cut.</span>
<a name="l00048"></a>00048 <span class="comment"> * \param[in] (x,y,z) the location of the Voronoi cell.</span>
<a name="l00049"></a>00049 <span class="comment"> * \return True if the cell still exists, false if the cell is deleted. */</span>
<a name="l00050"></a>00050 <span class="keyword">template</span>&lt;<span class="keyword">class</span> v_cell&gt;
<a name="l00051"></a><a class="code" href="structvoro_1_1wall__plane.html#a8d2515cef30dbd7594a4403d502b4fe5">00051</a> <span class="keywordtype">bool</span> <a class="code" href="structvoro_1_1wall__plane.html#a8d2515cef30dbd7594a4403d502b4fe5">wall_plane::cut_cell_base</a>(v_cell &amp;c,<span class="keywordtype">double</span> x,<span class="keywordtype">double</span> y,<span class="keywordtype">double</span> z) {
<a name="l00052"></a>00052         <span class="keywordtype">double</span> dq=2*(ac-x*xc-y*yc-z*zc);
<a name="l00053"></a>00053         <span class="keywordflow">return</span> c.nplane(xc,yc,zc,dq,w_id);
<a name="l00054"></a>00054 }
<a name="l00055"></a>00055 <span class="comment"></span>
<a name="l00056"></a>00056 <span class="comment">/** Tests to see whether a point is inside the cylindrical wall object.</span>
<a name="l00057"></a>00057 <span class="comment"> * \param[in] (x,y,z) the vector to test.</span>
<a name="l00058"></a>00058 <span class="comment"> * \return True if the point is inside, false if the point is outside. */</span>
<a name="l00059"></a><a class="code" href="structvoro_1_1wall__cylinder.html#a338b12542139088159acac3f5face2f7">00059</a> <span class="keywordtype">bool</span> <a class="code" href="structvoro_1_1wall__cylinder.html#a338b12542139088159acac3f5face2f7">wall_cylinder::point_inside</a>(<span class="keywordtype">double</span> x,<span class="keywordtype">double</span> y,<span class="keywordtype">double</span> z) {
<a name="l00060"></a>00060         <span class="keywordtype">double</span> xd=x-xc,yd=y-yc,zd=z-zc;
<a name="l00061"></a>00061         <span class="keywordtype">double</span> pa=(xd*xa+yd*ya+zd*za)*asi;
<a name="l00062"></a>00062         xd-=xa*pa;yd-=ya*pa;zd-=za*pa;
<a name="l00063"></a>00063         <span class="keywordflow">return</span> xd*xd+yd*yd+zd*zd&lt;rc*rc;
<a name="l00064"></a>00064 }
<a name="l00065"></a>00065 <span class="comment"></span>
<a name="l00066"></a>00066 <span class="comment">/** Cuts a cell by the cylindrical wall object. The cylindrical wall is</span>
<a name="l00067"></a>00067 <span class="comment"> * approximated by a single plane applied at the point on the cylinder which is</span>
<a name="l00068"></a>00068 <span class="comment"> * closest to the center of the cell. This works well for particle arrangements</span>
<a name="l00069"></a>00069 <span class="comment"> * that are packed against the wall, but loses accuracy for sparse particle</span>
<a name="l00070"></a>00070 <span class="comment"> * distributions.</span>
<a name="l00071"></a>00071 <span class="comment"> * \param[in,out] c the Voronoi cell to be cut.</span>
<a name="l00072"></a>00072 <span class="comment"> * \param[in] (x,y,z) the location of the Voronoi cell.</span>
<a name="l00073"></a>00073 <span class="comment"> * \return True if the cell still exists, false if the cell is deleted. */</span>
<a name="l00074"></a>00074 <span class="keyword">template</span>&lt;<span class="keyword">class</span> v_cell&gt;
<a name="l00075"></a><a class="code" href="structvoro_1_1wall__cylinder.html#ada478166ad7607c53d691608c7806cca">00075</a> <span class="keywordtype">bool</span> <a class="code" href="structvoro_1_1wall__cylinder.html#ada478166ad7607c53d691608c7806cca">wall_cylinder::cut_cell_base</a>(v_cell &amp;c,<span class="keywordtype">double</span> x,<span class="keywordtype">double</span> y,<span class="keywordtype">double</span> z) {
<a name="l00076"></a>00076         <span class="keywordtype">double</span> xd=x-xc,yd=y-yc,zd=z-zc;
<a name="l00077"></a>00077         <span class="keywordtype">double</span> pa=(xd*xa+yd*ya+zd*za)*asi;
<a name="l00078"></a>00078         xd-=xa*pa;yd-=ya*pa;zd-=za*pa;
<a name="l00079"></a>00079         pa=xd*xd+yd*yd+zd*zd;
<a name="l00080"></a>00080         <span class="keywordflow">if</span>(pa&gt;1e-5) {
<a name="l00081"></a>00081                 pa=2*(sqrt(pa)*rc-pa);
<a name="l00082"></a>00082                 <span class="keywordflow">return</span> c.nplane(xd,yd,zd,pa,w_id);
<a name="l00083"></a>00083         }
<a name="l00084"></a>00084         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00085"></a>00085 }
<a name="l00086"></a>00086 <span class="comment"></span>
<a name="l00087"></a>00087 <span class="comment">/** Tests to see whether a point is inside the cone wall object.</span>
<a name="l00088"></a>00088 <span class="comment"> * \param[in] (x,y,z) the vector to test.</span>
<a name="l00089"></a>00089 <span class="comment"> * \return True if the point is inside, false if the point is outside. */</span>
<a name="l00090"></a><a class="code" href="structvoro_1_1wall__cone.html#a5bcbbcdbe0c36285c6630dd92380a091">00090</a> <span class="keywordtype">bool</span> <a class="code" href="structvoro_1_1wall__cone.html#a5bcbbcdbe0c36285c6630dd92380a091">wall_cone::point_inside</a>(<span class="keywordtype">double</span> x,<span class="keywordtype">double</span> y,<span class="keywordtype">double</span> z) {
<a name="l00091"></a>00091         <span class="keywordtype">double</span> xd=x-xc,yd=y-yc,zd=z-zc;
<a name="l00092"></a>00092         <span class="keywordtype">double</span> pa=(xd*xa+yd*ya+zd*za)*asi;
<a name="l00093"></a>00093         xd-=xa*pa;yd-=ya*pa;zd-=za*pa;
<a name="l00094"></a>00094         pa*=gra;
<a name="l00095"></a>00095         <span class="keywordflow">if</span> (pa&lt;0) <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00096"></a>00096         pa*=pa;
<a name="l00097"></a>00097         <span class="keywordflow">return</span> xd*xd+yd*yd+zd*zd&lt;pa;
<a name="l00098"></a>00098 }
<a name="l00099"></a>00099 <span class="comment"></span>
<a name="l00100"></a>00100 <span class="comment">/** Cuts a cell by the cone wall object. The conical wall is</span>
<a name="l00101"></a>00101 <span class="comment"> * approximated by a single plane applied at the point on the cone which is</span>
<a name="l00102"></a>00102 <span class="comment"> * closest to the center of the cell. This works well for particle arrangements</span>
<a name="l00103"></a>00103 <span class="comment"> * that are packed against the wall, but loses accuracy for sparse particle</span>
<a name="l00104"></a>00104 <span class="comment"> * distributions.</span>
<a name="l00105"></a>00105 <span class="comment"> * \param[in,out] c the Voronoi cell to be cut.</span>
<a name="l00106"></a>00106 <span class="comment"> * \param[in] (x,y,z) the location of the Voronoi cell.</span>
<a name="l00107"></a>00107 <span class="comment"> * \return True if the cell still exists, false if the cell is deleted. */</span>
<a name="l00108"></a>00108 <span class="keyword">template</span>&lt;<span class="keyword">class</span> v_cell&gt;
<a name="l00109"></a><a class="code" href="structvoro_1_1wall__cone.html#ad39d47ee5d007dab3728e45efdaf0db7">00109</a> <span class="keywordtype">bool</span> <a class="code" href="structvoro_1_1wall__cone.html#ad39d47ee5d007dab3728e45efdaf0db7">wall_cone::cut_cell_base</a>(v_cell &amp;c,<span class="keywordtype">double</span> x,<span class="keywordtype">double</span> y,<span class="keywordtype">double</span> z) {
<a name="l00110"></a>00110         <span class="keywordtype">double</span> xd=x-xc,yd=y-yc,zd=z-zc;
<a name="l00111"></a>00111         <span class="keywordtype">double</span> xf,yf,zf,imoda;
<a name="l00112"></a>00112         <span class="keywordtype">double</span> pa=(xd*xa+yd*ya+zd*za)*asi;
<a name="l00113"></a>00113         xd-=xa*pa;yd-=ya*pa;zd-=za*pa;
<a name="l00114"></a>00114         pa=xd*xd+yd*yd+zd*zd;
<a name="l00115"></a>00115         <span class="keywordflow">if</span>(pa&gt;1e-5) {
<a name="l00116"></a>00116                 pa=1/sqrt(pa);
<a name="l00117"></a>00117                 imoda=sqrt(asi);
<a name="l00118"></a>00118                 xf=-sang*imoda*xa+cang*pa*xd;
<a name="l00119"></a>00119                 yf=-sang*imoda*ya+cang*pa*yd;
<a name="l00120"></a>00120                 zf=-sang*imoda*za+cang*pa*zd;
<a name="l00121"></a>00121                 pa=2*(xf*(xc-x)+yf*(yc-y)+zf*(zc-z));
<a name="l00122"></a>00122                 <span class="keywordflow">return</span> c.nplane(xf,yf,zf,pa,w_id);
<a name="l00123"></a>00123         }
<a name="l00124"></a>00124         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00125"></a>00125 }
<a name="l00126"></a>00126 
<a name="l00127"></a>00127 }
</pre></div></div>
</div>


<hr class="footer"/><address class="footer"><small>
Generated on Fri Sep 23 2011 22:49:06 for Voro++ by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
